package com.ermao.config;

import com.ermao.interceptor.GlobalInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * MVC 配置，主要用于拦截，但是由于前端配置的一些不支持和不熟悉
 * 微信小程序暂时无法通过 cookie-session 鉴权拦截
 * web 端的 PUT 也无法被拦截，拦截后会
 * @author Ermao
 * Date: 2021/9/3 11:12
 */
@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {

	@Resource
	private GlobalInterceptor globalInterceptor;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(globalInterceptor).addPathPatterns("/api/v1/admins/*")
				.excludePathPatterns("/api/v1/admins/categories")
				.excludePathPatterns("/api/v1/admins/cookies")
				.excludePathPatterns("/api/v1/admins/users/*");

		WebMvcConfigurer.super.addInterceptors(registry);
	}
}
